// dxdetect.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>

bool chechIfDx9Exists(void);
bool FileExists(const TCHAR *);

int _tmain(int argc, _TCHAR* argv[])
{
    if (chechIfDx9Exists())
	{
	    //d3d9.dll is allready in system32 path, let's delete included d3d9.dll
         if (FileExists(TEXT("d3d9.dll")))
		     DeleteFile(TEXT("d3d9.dll"));
	}
	return 0;
}

bool chechIfDx9Exists()
{
	TCHAR szPath[MAX_PATH];

	if(SUCCEEDED(SHGetFolderPath(NULL, 
								 CSIDL_SYSTEMX86, 
								 NULL, 
								 0, 
								 szPath))) 
	{
		PathAppend(szPath, TEXT("d3d9.dll"));
		if (FileExists(szPath))
		{
		    return true;
		}
	}
	return false;
}

bool FileExists(const TCHAR *fileName)
{
    DWORD       fileAttr;

    fileAttr = GetFileAttributes(fileName);
    if (0xFFFFFFFF == fileAttr)
        return false;
    return true;
}